import { mnetMsg } from "../typeDef"
import { mnetForwardReaderInterface } from "./mnetForwardReaderInterface"

export class mnetForwardReader {
    //Receiver name, needs to be unique within the cluster
    constructor(
      name:string,
      reader:mnetForwardReaderInterface
    ) {
        this.mName = name
        this.mReader = reader
    }

    //Subscribe to a notification type message
    subscribeNotify(msgName:string,recvCallback:(msg:mnetMsg)=>void) {
      this.mReader.subscribeNotify(
        this.mName,msgName,
        (msg)=>{
          recvCallback(msg)
        }
      )
    }

    //Subscribe to a request type message
    subscribeRequest(msgName:string,recvCallback:(msg:mnetMsg)=>mnetMsg) {
      this.mReader.subscribeRequest(
        this.mName,msgName,
        (msg)=>{
          return recvCallback(msg)
        }
      ) 
    }

  
    private mName:string
    private mReader:mnetForwardReaderInterface
}